Fix: OpenGL init for StealthTip - #4959
Conversation
| self.start_angle = start_angle | ||
| VMobject.__init__( | ||
| self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs | ||
| super(ArrowTip, self).__init__( |
There was a problem hiding this comment.
I suspect there might be a nicer fix for this - happy to take any suggestions, this just seemed like the smallest patch that seemed to work.
|
Here's an alternate suggestion: what if we made from abc import ABC, abstractmethod
class ArrowTip(VMobject, ABC, metaclass=ConvertToOpenGL):
r"""Base class for arrow tips.
.. seealso::
:class:`ArrowTriangleTip`
:class:`ArrowTriangleFilledTip`
:class:`ArrowCircleTip`
:class:`ArrowCircleFilledTip`
:class:`ArrowSquareTip`
:class:`ArrowSquareFilledTip`
:class:`StealthTip`
Examples
--------
Cannot be used directly, only intended for inheritance::
>>> tip = ArrowTip()
Traceback (most recent call last):
...
NotImplementedError: Has to be implemented in inheriting subclasses.
Instead, use one of the pre-defined ones, or make
a custom one like this: ........
"""
@abstractmethod
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
# ... rest of implementation ...This works well enough on my computer. If I try to render this scene with OpenGL, I get the expected image: class ArrowTest(Scene):
def construct(self):
arrow = Arrow(tip_shape=StealthTip)
self.add(arrow)and if I instead render this scene with OpenGL... class ArrowTest(Scene):
def construct(self):
arrow = Arrow(tip_shape=StealthTip)
arrow2 = Arrow(tip_shape=ArrowTip)
self.add(arrow)... I get the following error: │ 172 │ │ color = self.get_color() │
│ 173 │ │ style.update({"fill_color": color, "stroke_color": color}) │
│ 174 │ │ style.update(self.tip_style) │
│ ❱ 175 │ │ tip = tip_shape(length=tip_length, **style) │
│ 176 │ │ return tip │
│ 177 │ │
│ 178 │ def position_tip(self, tip: tips.ArrowTip, at_start: bool = False) -> tips.ArrowTip: │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: Can't instantiate abstract class ArrowTip without an implementation for abstract methods '__init__', '_original__init__'As far as I can tell, this doesn't break anything - at least not any tests - but then again there don't seem to be any non-graphical tests for Maybe this would be a good general approach to writing mobject mixins? |
Overview: What does this pull request change?
Fixes
StealthTipinitialization when using the OpenGL renderer.Previous initialization bypassed
ConvertToOpenGLmetaclass, which results in the following errorReviewer Checklist